﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyTiemVang.DTO;

namespace QuanLyTiemVang.DAO
{
    class DanhSachKhoanChiDAO
    {
        private static QUANLYTIEMVANGEntities dbContext = new QUANLYTIEMVANGEntities();

        public static void Insert(DANHSACHKHOANCHI dskc)
        {
            dbContext.DANHSACHKHOANCHIs.Add(dskc);
            dbContext.SaveChanges();
        }
        public static List<DANHSACHKHOANCHI> SelectAllDanhSachKhoanChi()
        {
            var query = from d in dbContext.DANHSACHKHOANCHIs
                        select d;

            if (query.ToList().Count == 0)
                return null;

            return query.ToList();
        }
        //tam
        public static DANHSACHKHOANCHI GetDanhSachKhoanChi(DateTime date)
        {
            DANHSACHKHOANCHI danhsach = new DANHSACHKHOANCHI();

            var query = from ds in dbContext.DANHSACHKHOANCHIs
                        where ds.NgayChi == date
                        select ds;
            if (query.Count() > 0)
            {
                return query.First();
            }
            return null;
        }

        public static void UpdateDanhSachKhoangChi(DANHSACHKHOANCHI dskc)
        {
            var query = dbContext.DANHSACHKHOANCHIs.Find(dskc.MaDanhSachKhoanChi);
            if (query != null)
            {
                query.TienChiPhieuChi = dskc.TienChiPhieuChi;
                query.TienChiPhieuHangGiaCong = dskc.TienChiPhieuHangGiaCong;
                query.TienChiPhieuMuaHang = dskc.TienChiPhieuMuaHang;
                query.TongTienChi = dskc.TongTienChi;
                dbContext.SaveChanges();
            }
        }
    }
}
